﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cmdb.keede.common;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Migrations;

namespace cmdb.keede.entity
{
    public static class CMDBInitializer
    {
        public static void Initialize(CMDBContext context)
        {
            context.Database.EnsureCreated();

            if (context.EnvironmentInfo.Any()) return;
            var envs = new[]
            {
                new EnvironmentInfo
                {
                    CreateTime = DateTime.Now,
                    Description = "Test ENV",
                    Name = "测试环境",
                    Status = EnumEnvironmentStatus.Enabled,
                    BusinessInfo = new BusinessInfo[]
                    {
                        new BusinessInfo
                        {
                            CreateTime = DateTime.Now,
                            Description = "B2C BUSINESS",
                            Name = "B2C业务",
                            PICName = "张三",
                            Status = EnumBusinessStatus.Enabled,
                            ApplicationInfo = new[]
                            {
                                new ApplicationInfo
                                {
                                    CreateTime = DateTime.Now,
                                    Description = "B2C.API",
                                    Name = "B2C.API",
                                    PICName = "李四",
                                    Port = "80",
                                    Status = EnumApplicationStatus.Enabled,
                                    Type = EnumApplicationType.ASPNETCORE,

                                }
                            }
                        }
                    }
                }
            };

            var hosts = new[]
            {
                new VirtualHostInfo
                {
                    AdminName="Administrator",
                    Area="SHA",
                    AssetId="0001",
                    CPU=4,
                    CreateTime=DateTime.Now,
                    DeviceType=EnumDeviceType.VirtualHost,
                    HardDiskSize=100,
                    InnerIP="192.168.117.100",
                    NetworkBandwidth=100,
                    OS=EnumOperationSystem.Windows,
                    OuterIP="192.168.117.100",
                    OSVersion="2008 R2",
                    RAM=16,
                    Password="123123123",
                    Remark="",
                    Status=EnumVirtualHostStatus.Assigned,
                },
                new VirtualHostInfo
                {
                    AdminName="Administrator",
                    Area="SHA",
                    AssetId="0001",
                    CPU=4,
                    CreateTime=DateTime.Now,
                    DeviceType=EnumDeviceType.VirtualHost,
                    HardDiskSize=100,
                    InnerIP="192.168.117.100",
                    NetworkBandwidth=100,
                    OS=EnumOperationSystem.Windows,
                    OuterIP="192.168.117.100",
                    OSVersion="2008 R2",
                    RAM=16,
                    Password="123123123",
                    Remark="",
                    Status=EnumVirtualHostStatus.Assigned

                },
                new VirtualHostInfo
                {
                    AdminName="Administrator",
                    Area="SHA",
                    AssetId=Guid.NewGuid().ToString(),
                    CPU=4,
                    CreateTime=DateTime.Now,
                    DeviceType=EnumDeviceType.VirtualHost,
                    HardDiskSize=100,
                    InnerIP="192.168.117.100",
                    NetworkBandwidth=100,
                    OS=EnumOperationSystem.Windows,
                    OuterIP="192.168.117.100",
                    OSVersion="2008 R2",
                    RAM=16,
                    Password="123123123",
                    Remark="",
                    Status=EnumVirtualHostStatus.Assigned

                },
                new VirtualHostInfo
                {
                    AdminName="Administrator",
                    Area="SHA",
                    AssetId=Guid.NewGuid().ToString(),
                    CPU=4,
                    CreateTime=DateTime.Now,
                    DeviceType=EnumDeviceType.VirtualHost,
                    HardDiskSize=100,
                    InnerIP="192.168.117.100",
                    NetworkBandwidth=100,
                    OS=EnumOperationSystem.Windows,
                    OuterIP="192.168.117.100",
                    OSVersion="2008 R2",
                    RAM=16,
                    Password="123123123",
                    Remark="",
                    Status=EnumVirtualHostStatus.Assigned

                },
                new VirtualHostInfo
                {
                    AdminName="Administrator",
                    Area="SHA",
                    AssetId=Guid.NewGuid().ToString(),
                    CPU=4,
                    CreateTime=DateTime.Now,
                    DeviceType=EnumDeviceType.VirtualHost,
                    HardDiskSize=100,
                    InnerIP="192.168.117.100",
                    OS=EnumOperationSystem.Windows,
                    OuterIP="192.168.117.100",
                    OSVersion="2008 R2",
                    RAM=16,
                    Password="123123123",
                    Remark="",
                    Status=EnumVirtualHostStatus.Assigned

                },
                new VirtualHostInfo
                {
                    AdminName="Administrator",
                    Area="SHA",
                    AssetId=Guid.NewGuid().ToString(),
                    CPU=4,
                    CreateTime=DateTime.Now,
                    DeviceType=EnumDeviceType.VirtualHost,
                    HardDiskSize=100,
                    InnerIP="192.168.117.100",
                    NetworkBandwidth=100,
                    OS=EnumOperationSystem.Windows,
                    OuterIP="192.168.117.100",
                    OSVersion="2008 R2",
                    RAM=16,
                    Password="123123123",
                    Remark="",
                    Status=EnumVirtualHostStatus.Assigned

                },
                new VirtualHostInfo
                {
                    AdminName="Administrator",
                    Area="SHA",
                    AssetId=Guid.NewGuid().ToString(),
                    CPU=4,
                    CreateTime=DateTime.Now,
                    DeviceType=EnumDeviceType.VirtualHost,
                    HardDiskSize=100,
                    InnerIP="192.168.117.100",
                    NetworkBandwidth=100,
                    OS=EnumOperationSystem.Windows,
                    OuterIP="192.168.117.100",
                    OSVersion="2008 R2",
                    RAM=16,
                    Password="123123123",
                    Remark="",
                    Status=EnumVirtualHostStatus.Assigned

                },
                new VirtualHostInfo
                {
                    AdminName="Administrator",
                    Area="SHA",
                    AssetId=Guid.NewGuid().ToString(),
                    CPU=4,
                    CreateTime=DateTime.Now,
                    DeviceType=EnumDeviceType.VirtualHost,
                    HardDiskSize=100,
                    InnerIP="192.168.117.100",
                    NetworkBandwidth=100,
                    OS=EnumOperationSystem.Windows,
                    OuterIP="192.168.117.100",
                    OSVersion="2008 R2",
                    RAM=16,
                    Password="123123123",
                    Remark="",
                    Status=EnumVirtualHostStatus.Assigned

                },
                new VirtualHostInfo
                {
                    AdminName="Administrator",
                    Area="SHA",
                    AssetId=Guid.NewGuid().ToString(),
                    CPU=4,
                    CreateTime=DateTime.Now,
                    DeviceType=EnumDeviceType.VirtualHost,
                    HardDiskSize=100,
                    InnerIP="192.168.117.100",
                    NetworkBandwidth=100,
                    OS=EnumOperationSystem.Windows,
                    OuterIP="192.168.117.100",
                    OSVersion="2008 R2",
                    RAM=16,
                    Password="123123123",
                    Remark="",
                    Status=EnumVirtualHostStatus.Assigned

                },
                new VirtualHostInfo
                {
                    AdminName="Administrator",
                    Area="SHA",
                    AssetId=Guid.NewGuid().ToString(),
                    CPU=4,
                    CreateTime=DateTime.Now,
                    DeviceType=EnumDeviceType.VirtualHost,
                    HardDiskSize=100,
                    InnerIP="192.168.117.100",
                    NetworkBandwidth=100,
                    OS=EnumOperationSystem.Windows,
                    OuterIP="192.168.117.100",
                    OSVersion="2008 R2",
                    RAM=16,
                    Password="123123123",
                    Remark="",
                    Status=EnumVirtualHostStatus.Assigned

                },
                new VirtualHostInfo
                {
                    AdminName="Administrator",
                    Area="SHA",
                    AssetId=Guid.NewGuid().ToString(),
                    CPU=4,
                    CreateTime=DateTime.Now,
                    DeviceType=EnumDeviceType.VirtualHost,
                    HardDiskSize=100,
                    InnerIP="192.168.117.100",
                    NetworkBandwidth=100,
                    OS=EnumOperationSystem.Windows,
                    OuterIP="192.168.117.100",
                    OSVersion="2008 R2",
                    RAM=16,
                    Password="123123123",
                    Remark="",
                    Status=EnumVirtualHostStatus.Assigned

                },
                new VirtualHostInfo
                {
                    AdminName="Administrator",
                    Area="SHA",
                    AssetId=Guid.NewGuid().ToString(),
                    CPU=4,
                    CreateTime=DateTime.Now,
                    DeviceType=EnumDeviceType.VirtualHost,
                    HardDiskSize=100,
                    InnerIP="192.168.117.100",
                    NetworkBandwidth=100,
                    OS=EnumOperationSystem.Windows,
                    OuterIP="192.168.117.100",
                    OSVersion="2008 R2",
                    RAM=16,
                    Password="123123123",
                    Remark="",
                    Status=EnumVirtualHostStatus.Assigned

                }
            };

            context.VirtualHostInfo.AddRange(hosts);

            var app = envs.First().BusinessInfo.First().ApplicationInfo.First();

            foreach (var host in hosts)
            {
                app.ApplicationVirtualHosts.Add(new ApplicationVirtualHost
                {
                    ApplicationId = app.Id,
                    VirtualHostId = host.Id
                });
            }

            context.EnvironmentInfo.AddRange(envs);
            context.SaveChanges();
        }
    }
}
